home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC_Samples / palette / dibview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  3.6 KB  |  150 lines

  1. // dibview.cpp : implementation of the CDibView class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1999 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14.  
  15. #include "dibdoc.h"
  16. #include "dibview.h"
  17. #include "dibapi.h"
  18. #include "mainfrm.h"
  19.  
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char BASED_CODE THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CDibView
  27.  
  28. IMPLEMENT_DYNCREATE(CDibView, CScrollView)
  29.  
  30. BEGIN_MESSAGE_MAP(CDibView, CScrollView)
  31.     //{{AFX_MSG_MAP(CDibView)
  32.     ON_MESSAGE(WM_USER, OnDoRealize)
  33.     //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CDibView construction/destruction
  38.  
  39. CDibView::CDibView()
  40. {
  41. }
  42.  
  43. CDibView::~CDibView()
  44. {
  45. }
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CDibView drawing
  49.  
  50. void CDibView::OnDraw(CDC* pDC)
  51. {
  52.     CDibDoc* pDoc = GetDocument();
  53.  
  54.     HDIB hDIB = pDoc->GetHDIB();
  55.     if (hDIB != NULL)
  56.     {
  57.         LPSTR lpDIB = (LPSTR)(LPSTR)hDIB;
  58.         int cxDIB = (int) ::DIBWidth(lpDIB);         // Size of DIB - x
  59.         int cyDIB = (int) ::DIBHeight(lpDIB);        // Size of DIB - y
  60.  
  61.         CRect rcDIB;
  62.         rcDIB.top = rcDIB.left = 0;
  63.         rcDIB.right = cxDIB;
  64.         rcDIB.bottom = cyDIB;
  65.         CRect rcDest;
  66.         rcDest = rcDIB;
  67.         ::PaintDIB(pDC->m_hDC, &rcDest, pDoc->GetHDIB(), &rcDIB, pDoc->GetDocPalette());
  68.     }
  69. }
  70.  
  71.  
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CDibView commands
  74.  
  75.  
  76. LRESULT CDibView::OnDoRealize(WPARAM wParam, LPARAM)
  77. {
  78.     if(!m_bUsePalette)
  79.         return 0;
  80.  
  81.     ASSERT(wParam != NULL);
  82.     CDibDoc* pDoc = GetDocument();
  83.     
  84.     if (pDoc->GetHDIB() == NULL)
  85.         return 0L;  // must be a new document
  86.  
  87.     CPalette* pPal = pDoc->GetDocPalette();
  88.     if (pPal != NULL)
  89.     {
  90.         CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
  91.         ASSERT_KINDOF(CMainFrame, pAppFrame);
  92.  
  93.         CClientDC appDC(pAppFrame);
  94.         // All views but one should be a background palette.
  95.         // wParam contains a handle to the active view, so the SelectPalette
  96.         // bForceBackground flag is FALSE only if wParam == m_hWnd (this view)
  97.         CPalette* oldPalette;
  98.  
  99.         oldPalette = appDC.SelectPalette(pPal, ((HWND)wParam) != m_hWnd);
  100.         if (oldPalette)
  101.         {
  102.             UINT nColorsChanged;
  103.             nColorsChanged = appDC.RealizePalette();
  104.             if (nColorsChanged > 0)
  105.                 pDoc->UpdateAllViews(NULL);
  106.             appDC.SelectPalette(oldPalette, TRUE);
  107.         }
  108.         else
  109.         {
  110.             TRACE0("\tSelectPalette failed in CDibView::OnPaletteChanged\n");
  111.         }
  112.     }
  113.     return 0L;
  114. }
  115.  
  116. void CDibView::OnInitialUpdate()
  117. {
  118.     CScrollView::OnInitialUpdate();
  119.     ASSERT(GetDocument() != NULL);
  120.  
  121.     SetScrollSizes(MM_TEXT, GetDocument()->GetDocSize());
  122.  
  123.     ShowPicture(TRUE); // show picture
  124. }
  125.  
  126.  
  127. void CDibView::OnActivateView(BOOL bActivate, CView* pActivateView,
  128.                     CView* pDeactiveView)
  129. {
  130.     CScrollView::OnActivateView(bActivate, pActivateView, pDeactiveView);
  131.  
  132.     if (bActivate)
  133.     {
  134.         ASSERT(pActivateView == this);
  135.         OnDoRealize((WPARAM)m_hWnd, 0);   // same as SendMessage(WM_DOREALIZE);
  136.     }
  137. }
  138.  
  139. void CDibView::ShowPicture(BOOL bUsePalette)
  140. {
  141.     m_bUsePalette = bUsePalette;
  142.     CDibDoc* pDoc = (CDibDoc*)GetDocument();
  143.     if(pDoc)
  144.     {
  145.         pDoc->OnOpenFile(_T(".\\forest.bmp"));
  146.         Invalidate();
  147.     }
  148. }
  149.  
  150.